package com.zx.sp_mybatisplus.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zx.sp_mybatisplus.pojo.User;
import com.zx.sp_mybatisplus.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Controller
@RequestMapping("/user/")
public class UserController {
    @Autowired
    private UserService userService;


    @RequestMapping("list")
    public String list(Model model){
        List<User> ulist = userService.findAllUser();
        model.addAttribute("ulist",ulist);
        return "userlist";
    }

    @RequestMapping("details/{uid}")
    public String details(@PathVariable("uid") Integer id, Model model){
        User user = userService.getById(id);
        model.addAttribute("user",user);
        return "details";
    }

    @RequestMapping("listpages/{current}")
    public String listpages(@PathVariable("current") Integer current, Model model){
        Page<User> page=new Page<User>(current,2);
        Page<User> page1 = userService.page(page);
        model.addAttribute("upage",page1);
        return "listpage";
    }
}
